package com.example.distributezklock.controller;


import com.example.distributezklock.lock.ZKLock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author caryguan
 * @version V1.0
 * @Package com.example.distributezklock.controller
 * @date 2020/10/9 1:20
 */
@RestController
@Slf4j
public class ZookeeperController {

    @RequestMapping("zkLock")
    public String zookeeperLock() {
        log.info("我进入了方法");
        try (ZKLock zkLock = new ZKLock()) {
            if (zkLock.getLock("order")) {
                log.info("我获取了锁");
                Thread.sleep(15000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("方法执行完成");
        return "方法执行完成";
    }
}